//
//  CompoundDetailBottomListView.swift
//  LeGou
//
//  Created by lxm on 2022/11/11.
//

import UIKit

class CompoundDetailBottomListView: ZMXIBView, UITableViewDelegate, UITableViewDataSource {

    //MARK: --------------------属性--------------------
    let headerHeight : CGFloat = 29
    
    let cellHeight : CGFloat = 32
    
    var listData = [(String, String, String)]() {
        didSet {
            tableView.reloadData()
            self.snp.updateConstraints { make in
                make.height.equalTo(cellHeight * CGFloat(listData.count) + headerHeight)
            }
        }
    }
    //MARK: --------------------UI控件--------------------
    
    @IBOutlet weak var tableView: UITableView!
    //MARK: --------------------生命周期--------------------
    override func awakeFromNib() {
        super.awakeFromNib()
        setUI()
        bindAction()
        addConstraints()
    }

    //MARK: --------------------UI--------------------
    func setUI() {
        tableView.delegate = self
        tableView.dataSource = self
        tableView.zm.register(nibName: "CompoundDetailBottomListCell", reuserId: "CompoundDetailBottomListCell")
        tableView.isUserInteractionEnabled = false
    }
    
    func addConstraints() {
        snp.makeConstraints { make in
            make.height.equalTo(headerHeight)
        }
    }
    
    //MARK: --------------------methods--------------------
    func bindAction() {
        
    }
    //MARK: --------------------delegate--------------------
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        listData.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "CompoundDetailBottomListCell") as! CompoundDetailBottomListCell
        let data = listData[indexPath.row]
        cell.one.text = data.0
        cell.two.text = data.1
        cell.three.text = data.2
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 32
    }

}
